module doa_estimator (
    input  wire        clk,
    input  wire        rst_n,
    input  wire        freq_vld,
    input  wire [31:0] freq_real [15:0][127:0],
    input  wire [31:0] freq_imag [15:0][127:0],
    input  wire [15:0] energy_levels,
    
    // DOA输出
    output wire [8:0]  estimated_angle,     // 估计角度(0-359)
    output wire [7:0]  angle_confidence,    // 置信度(0-255)
    output wire        doa_vld,
    output wire [2:0]  doa_state,          // 状态机
    
    // 多声源支持
    output wire [8:0]  secondary_angle,     // 第二声源角度
    output wire [7:0]  secondary_confidence
);

// 子模块
covariance_calculator u_covariance (
    .clk(clk),
    .rst_n(rst_n),
    .freq_vld(freq_vld),
    .freq_real(freq_real),
    .freq_imag(freq_imag),
    .cov_matrix_real(cov_real),
    .cov_matrix_imag(cov_imag),
    .cov_vld(cov_vld)
);

music_algorithm u_music (
    .clk(clk),
    .rst_n(rst_n),
    .cov_vld(cov_vld),
    .cov_matrix_real(cov_real),
    .cov_matrix_imag(cov_imag),
    .estimated_angle(estimated_angle),
    .angle_confidence(angle_confidence),
    .doa_vld(doa_vld)
);

angle_tracker u_tracker (
    .clk(clk),
    .rst_n(rst_n),
    .doa_vld(doa_vld),
    .new_angle(estimated_angle),
    .confidence(angle_confidence),
    .tracked_angle(final_angle),
    .track_vld(track_vld)
);

endmodule